﻿var img_url = "";


$(function () {
   

});

function Notic(type, message)
{
    var shortCutFunction = type;//'success','error','warning','info'

    var msg = "";
    var title = message;

    toastr.options = {
        "closeButton": true,
        "debug": false,
        "progressBar": true,
        "positionClass": "toast-top-center",
        "onclick": null,
        "showDuration": "1000",
        "hideDuration": "1000",
        "timeOut": "1000",
        "extendedTimeOut": "1000",
        "showEasing": "swing",
        "hideEasing": "linear",
        "showMethod": "fadeIn",
        "hideMethod": "fadeOut"
    }
    $("#toastrOptions").text("Command: toastr["
            + shortCutFunction
            + "](\""
            + msg
            + (title ? "\", \"" + title : '')
            + "\")\n\ntoastr.options = "
            + JSON.stringify(toastr.options, null, 2)
    );
    var $toast = toastr[shortCutFunction](msg, title);
    ////console.log($toast);// Wire up an event handler to a button in the toast, if it exists

}


function GetUserStatus(status)
{

    switch (status) {

        case 0: return "无效";
        case 1: return "正常";


    }


}
function GetOrderStatus(status)
{
    switch (status) {

        case 0: return "无效";
        case 1: return "待支付";
        case 2: return "已付定金";
        case 3: return "已支付";


    }

}
function GetDeliverStatus(status)
{
    switch (status) {

        case 0: return "未发货";
        case 1: return "已发货";
       
    }

}
function GetQuesStatus(status) {
    switch (status) {

        case 0: return "已驳回";
        case 1: return "待审核";
        case 2: return "已通过";

    }

}
function GetInteractionType(status)
{
    switch (status)
    {
        case 0: return "爆料台";
        case 1: return "意见建议";
        case 2: return "用户咨询";
    }
}
function GetInteractionStatus(status) {
    switch (status) {
        case 0: return "无效";
        case 1: return "未审核";
        case 2: return "已通过";
    }
}
function GetListValue(obj)
{
    var r = "";

    if ($(obj) == null || $(obj) == undefined) {

        return r;

    }


    $(obj).each(function ()
    {

        r += $(this).val() + ",";

      
    })

    if (r.length > 0) {

        r = r.substr(0, r.length - 1);
    }
    return r;
}
function checkPhone(phone) {

   
    if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(phone)) {

        return false;
    }
    else {

        return true
    }
}
function checkPic(filename)
{
    var ext = /(.*)\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$/.test(filename.toLowerCase());

    return ext;
}
function checkfile(filename) {
    var ext = /(.*)\.(pdf)$/.test(filename.toLowerCase());

    return ext;
}
function checkfile2(filename) {
    var ext = /(.*)\.(pdf|doc|docx|ppt|pptx)$/.test(filename.toLowerCase());

    return ext;
}
function LoadingInit()
{
    $('#loading').modal({ backdrop: 'static', keyboard: false, show: false });
}

function LoadingShow(title)
{
    if (title != null && title != undefined)
    {
        $("#loading_content").html(title);
       
    }

    $('#loading').modal("show");

}
function LoadingHide()
{
  
    
    setTimeout(function () { $("#loading").modal("hide");  }, 500);
    //$('#loading').modal('hide');
   
}
$("#loading").on("hidden.bs.modal", function () {
    
    console.log("hidebs");
})


function ImgPreView(file,obj,data)
{
    var reader = new FileReader();

    reader.onload = function (e)
    {
       

        $(obj).attr("src", e.target.result);   

        $(obj).show();
        return e.target.result.split(',')[1];
    }

    reader.readAsDataURL(file);

}

function ImgUpload(file,road,needloding)
{
    img_url = "";
    var form = new FormData();

    form.append("file1", file);

    form.append("road", road);

   
    if (needloding != false)
    {
        LoadingShow("图片上传中···");
    }
    $.ajax({
        url: "../BaseFile/ImgUploadFile",
        data: form,
        contentType: false,//注意
        processData: false,
        dataType:"json",
        type: "post",     
        success: function (data)
        {
           

            if (data.IsError)
            {

                Notic('error', data.Message);
            }
            else
            {
              
                img_url = data.Result;

               
            }           
        },
        complete: function (data)
        {
            if (needloding != false)
            {
                LoadingHide();
            }
        }

    });
}

function LightHigh(str)
{
   
    var flag = "<span style='color:#1714c7;font-weight:bold;padding:0;'>";

    var flag_end = "</span>";

   // str = str.replace(new RegExp(/(###)/g), flag);
  

    str = str.split("###").join(flag);

    str = str.split("$$$").join(flag_end);

   


    return str;
};
function LightHigh2(str, flag, flag_end) {

  

    str = str.split("###").join(flag);

    str = str.split("$$$").join(flag_end);




    return str;
};

function LightNormal(str) {
    var flag = "";
    var flag_end = "";

    // str = str.replace(new RegExp(/(###)/g), flag);


    str = str.split("###").join(flag);

    str = str.split("$$$").join(flag_end);

    return str;
};
function GetYears(obj,pre,after)
{

    var current = new Date().getFullYear();

    var html = "";

    for (var j = pre; j > 0; j--)
    {
        html += "<option value='" + (current - j) + "'>" + (current - j)+"</option>";

    }
    html += "<option value='" + (current) + "' selected>" + (current) + "</option>";

    for (var i = 1; i <=after; i++)
    {
        html += "<option value='" + (current + i) + "'>" + (current + i)+"</option>";

    }
    console.log(html);
    $(obj).html(html);

}


function DataPickerInit() {


    $('.LDD').datepicker({
        startView: 0,
        todayBtn: "linked",
        keyboardNavigation: false,
        forceParse: false,
        autoclose: true,
        format: "yyyy-mm-dd",
        language: "zh-CN",
        forceParse: true,
        todayHighlight: true,
        clearBtn: true
    });

}


function ResultHandler(result,ismobile)
{
    console.log(result);

   if (result.IsError)
   {
       if (result.Value != 4004)
       {

           Notic('error', result.Message);

           return;
       }
       var local_url = window.location.href;

       var url = "/Result/Error?type=1005";

       location = url;
    }

}


function UniqueByte(arr) {


   
        var hash = [];
        for (var i = 0; i < arr.length; i++) {
            if (hash.indexOf(arr[i]) == -1) {
                hash.push(arr[i]);
            }
        }
        return hash;
    
}

function WindowClose()
{
  

        var userAgent = navigator.userAgent;
        if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") != -1) {
            window.location.href = "about:blank";
        } else if (userAgent.indexOf('Android') > -1 || userAgent.indexOf('Linux') > -1) {
            window.opener = null; window.open('about:blank', '_self', '').close();
        } else
        {
            window.opener = null;
            window.open("about:blank", "_self");
            window.close();
        }


}
function GetSourceName(url)
{
    var r = "未知";
    for (var o in site_res)
    {
        if (url.indexOf(site_res[o].k) !== -1)
        {

            r = site_res[o].v;
        }
    }
    return r;

}

function SetTitle(html) {

    var obj = $("#center_container");

    if (obj != null) {
        $(obj).html(html);

    }
}
function RemoveTitle(html) {

    var obj = $("#center_container");

    if (obj != null) {
        $(obj).empty();

    }
}
function SetOptionMenu(html)
{

    var obj = $("#right_container");

    if (obj != null) {
        $(obj).html(html);

    }
}
function RemoveOptionMenu()
{
    var obj = $("#right_container");

    if (obj != null)
    {
        $(obj).empty();

    }
}


function GetGreeceNum(num)
{
    var r = "";
    switch (num)
    {       
        case 1: r = "Ⅰ"; break;
        case 2: r = "Ⅱ"; break;
        case 3: r = "Ⅲ"; break;
        case 4: r = "Ⅳ"; break;
        case 5: r = "Ⅶ"; break;
        case 6: r = "Ⅷ"; break;
        case 7: r = "Ⅸ"; break;
        case 8: r = "Ⅹ"; break;
        case 9: r = "Ⅺ"; break;
        case 10: r = "Ⅻ"; break;
    }

    return r;
}

function login(obj)
{
    if ($("#name").val() == "")
    {
        Notic('error', '用户名不能为空');
        return;
    }
    if ($("#pw").val() == "")
    {
        Notic('error', '密码不能为空');
        return;
    }
    $(obj).attr("disabled", "disabled");
    $(obj).val("登陆中。。。");
    $.ajax({

        url: "/Home/MloginDo",
        data: {
            "name": $("#name").val(),
            "pw": $("#pw").val()
        },
        dataType: "json",
        cache: false,
        type: "post",
        success: function (data) {

            if (data.IsError) {

                Notic('error', data.Message);
                $(obj).val("登陆");
                $(obj).removeAttr("disabled");
            }
            else {
                $(obj).val("登陆成功");
                window.open("/DocManager", '_top');
            }
        },
        error: function ()
        {
            Notic('error', '系统繁忙');
            $(obj).val("登陆");
            $(obj).removeAttr("disabled");
        }
    });

}
